import { InputItem } from "input_item.slint";
import { Button } from "std-widgets.slint";
import { SelectItem } from "select_item.slint";

export struct Config {
    host: string,
    port: string,
    user: string,
    password: string,
    database: string,
    sqltype: string,
    export: string,
}

export component Form {
    in-out property <string> host: "";
    in-out property <string> port: "";
    in-out property <string> user: "";
    in-out property <string> password: "";
    in-out property <string> database: "";
    in-out property <string> datatype: "mysql";
    in-out property <string> export: "word";
    out property <Config> config;

    callback confirm(Config);

    VerticalLayout {
        spacing: 16px;

        dt := SelectItem {
            label: "类型:";
            value: datatype;
            model: ["Mysql", "Sql Server"];
        }

        h := InputItem {
            label: "地址: ";
            value: host;
        }

        pp := InputItem {
            label: "端口: ";
            value: port;
        }

        u := InputItem {
            label: "用户名: ";
            value: user;
        }

        pw := InputItem {
            label: "密码: ";
            value: password;
        }

        db := InputItem {
            label: "数据库: ";
            value: database;
        }

        ex := SelectItem {
            label: "导出:";
            value: export;
            model: ["Word", "Markdown", "HTML", "Excel"];
        }

        Button {
            text: "生成";
            primary: true;
            clicked => {
                root.config = {
                    host: h.value,
                    port: pp.value,
                    user: u.value,
                    password: pw.value,
                    database: db.value,
                    sqltype: dt.value,
                    export: ex.value,
                };
                confirm(root.config);
            }
        }
    }
}
